import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate";
import request from "../utils/request";
import "../utils/api"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    indexData:[]
  },
  mutations: {
    // 给首页的数据进行赋值
    getIndexData(state, payload) {
      state.indexData = payload
    }
  },
  actions: {
    // 获取首页的数据
    getIndexData() {
      request.get("/api/list").then(res => {
        this.commit("getIndexData",res.data.data)
      })
    }
  },
  modules: {
  },
  plugins: [createPersistedState()],
})
